#include<stdio.h>
#include<stdlib.h>
int cam(const void* e1, const void* e2) {
	return *(int*)e1 - *(int*)e2;
}
void swap(char* buff1, char* buff2, size_t width) {
	for (int i = 0; i < width; i++) {
		char tmp = *buff1;
		*buff1 = *buff2;
		*buff2 = tmp;
		buff1++;
		buff2++;
	}
}
void bubblesort(void* base, size_t sz ,size_t width, int (*cam)(void* e1,void* e2)){
	size_t i = 0;
	for (i = 0; i < sz - 1; i++) {
		for (int j = 0; j < sz - i - 1; j++) {
			if (cam((char*)base + j * width, (char*)base + (j + 1) * width)>0) {
				swap((char*)base + j * width, (char*)base + (j + 1) * width,width);
			}
		}
	}
}
void test() {
	int arr[] = { 9,8,7,6,5 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubblesort(arr, sz, sizeof(arr[0]), cam);
	for (int i = 0; i < 5; i++) {
		printf("%d ", arr[i]);
	}
}
int main() {
	test();
	
	return 0;
}